﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../macro/head.h"
#include "../impl/head.h"
#include "../variant/head.h"
#include "property_impl.h"

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos_box
{
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    static property_impl::POOL * pool_ptr = 0;

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    property_impl::property_impl()
    {
        init_data();
    }

    property_impl::~property_impl()
    {
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    int property_impl::get_addr( POOL *** pppPool, LIST *** pppList )
    {
        int ret = 0;
        if( pppPool )
        {
            *pppPool = &pool_ptr;
        }
        if( pppList )
        {
            *pppList = 0;
        }
        return ret;
    }

    int property_impl::init()
    {
        int ret = 0;
        return ret;
    }

    int property_impl::term()
    {
        int ret = 0;

        release_all();
        init_data();

        return ret;
    }

    int property_impl::init_data()
    {
        m_name_iter = m_name_map.end();
        m_id_iter = m_id_map.end();
        return 0;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // name index get
    // 
    
    const char * property_impl::str( const char * lpszName, char * lpszValue, int nBufSize, int * lpnSizeNeeded )
    {
        i_variant * pV = vt( lpszName );
        const char * pR = 0;
        if( pV )
        {
            pR = pV->str( lpszValue, nBufSize, lpnSizeNeeded );
        }
        return pR;
    }

    xos::i_release * property_impl::obj( const char * lpszName, xos::i_release ** ppv )
    {
        i_variant * pV = vt( lpszName );
        xos::i_release * pR = 0;
        if( pV )
        {
            pR = pV->obj( ppv );
        }
        return pR;
    }

    xos_box::i_list * property_impl::list( const char * lpszName, xos_box::i_list ** ppv )
    {
        i_variant * pVT = vt( lpszName );
        xos_box::i_list * pR = 0;
        if( pVT )
        {
            pR = pVT->list( 0 );
        }
        if( ppv )
        {
            *ppv = pR;
        }
        return pR;
    }

    i_property * property_impl::prop( const char * lpszName, i_property ** ppv )
    {
        i_variant * pVT = vt( lpszName );
        i_property * pR = 0;
        if( pVT )
        {
            pR = pVT->prop( 0 );
        }
        if( ppv )
        {
            *ppv = pR;
        }
        return pR;
    }

    v_create property_impl::fun( const char * lpszName, v_create * pv )
    {
        i_variant * pV = vt( lpszName );
        v_create pR = 0;
        if( pV )
        {
            pR = pV->fun( pv );
        }
        return pR;
    }

    double property_impl::dbl( const char * lpszName, double * lpdValue )
    {
        i_variant * pV = vt( lpszName );
        double dl = 0.0;
        if( pV )
        {
            dl = pV->dbl( lpdValue );
        }
        return dl;
    }

    float property_impl::flt( const char * lpszName, float * lpfValue )
    {
        i_variant * pV = vt( lpszName );
        float ft = 0.0f;
        if( pV )
        {
            ft = pV->flt( lpfValue );
        }
        return ft;
    }

    int property_impl::it( const char * lpszName, int  * lpnValue )
    {
        i_variant * pV = vt( lpszName );
        int i = 0;
        if( pV )
        {
            i = pV->it( lpnValue );
        }
        return i;
    }

    xos::xos_u64 * property_impl::u64_ptr( const char * lpszName, xos::xos_u64 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_u64 * pRet = 0;
        if( pV )
        {
            pRet = pV->u64_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i64 * property_impl::i64_ptr( const char * lpszName, xos::xos_i64 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_i64 * pRet = 0;
        if( pV )
        {
            pRet = pV->i64_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_u32 * property_impl::u32_ptr( const char * lpszName, xos::xos_u32 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_u32 * pRet = 0;
        if( pV )
        {
            pRet = pV->u32_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i32 * property_impl::i32_ptr( const char * lpszName, xos::xos_i32 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_i32 * pRet = 0;
        if( pV )
        {
            pRet = pV->i32_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_u16 * property_impl::u16_ptr( const char * lpszName, xos::xos_u16 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_u16 * pRet = 0;
        if( pV )
        {
            pRet = pV->u16_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i16 * property_impl::i16_ptr( const char * lpszName, xos::xos_i16 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_i16 * pRet = 0;
        if( pV )
        {
            pRet = pV->i16_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_u8 * property_impl::u8_ptr( const char * lpszName, xos::xos_u8 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_u8 * pRet = 0;
        if( pV )
        {
            pRet = pV->u8_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i8 * property_impl::i8_ptr( const char * lpszName, xos::xos_i8 ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        xos::xos_i8 * pRet = 0;
        if( pV )
        {
            pRet = pV->i8_ptr( lppRet );
        }
        return pRet;
    }

    char * property_impl::char_array( const char * lpszName, char ** lppRet, int * lpnSize, int * lpnLen )
    {
        i_variant * pV = vt( lpszName );
        char * pRet = 0;
        if( pV )
        {
            pRet = pV->char_array( lppRet, lpnSize, lpnLen );
        }
        return pRet;
    }

    char * property_impl::bin_ptr( const char * lpszName, char ** lppRet, int * lpnSize, int * lpnLen )
    {
        i_variant * pV = vt( lpszName );
        char * pRet = 0;
        if( pV )
        {
            pRet = pV->bin_ptr( lppRet, lpnSize, lpnLen );
        }
        return pRet;
    }

    double * property_impl::dbl_ptr( const char * lpszName, double ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        double * pRet = 0;
        if( pV )
        {
            pRet = pV->dbl_ptr( lppRet );
        }
        return pRet;
    }

    float * property_impl::flt_ptr( const char * lpszName, float ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        float * pRet = 0;
        if( pV )
        {
            pRet = pV->flt_ptr( lppRet );
        }
        return pRet;
    }

    bool * property_impl::bool_ptr( const char * lpszName, bool ** lppRet )
    {
        i_variant * pV = vt( lpszName );
        bool * pRet = 0;
        if( pV )
        {
            pRet = pV->bool_ptr( lppRet );
        }
        return pRet;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // name index set
    // 

    int property_impl::set( const char * lpszName, const char * lpszValue )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpszValue );
        return 0;
    }

    int property_impl::set_obj( const char * lpszName, xos::i_release * pv, bool bAutoRelease )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_obj( pv, bAutoRelease );
        return 0;
    }

    int property_impl::set_list( const char * lpszName, xos_box::i_list * pv, bool bAutoRelease )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_list( pv, bAutoRelease );
        return 0;
    }

    int property_impl::set_prop( const char * lpszName, i_property * pv, bool bAutoRelease )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_prop( pv, bAutoRelease );
        return 0;
    }

    int property_impl::set( const char * lpszName, i_variant * pv )
    {
        i_variant * pVt = remove( lpszName );
        xos_stl::release_interface( pVt );
        m_name_map[lpszName] = pv;
        return 0;
    }

    int property_impl::set( const char * lpszName, v_create pv )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( pv );
        return 0;
    }

    int property_impl::set( const char * lpszName, double value )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( value );
        return 0;
    }

    int property_impl::set( const char * lpszName, float value )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( value );
        return 0;
    }

    int property_impl::set( const char * lpszName, int value )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( value );
        return 0;
    }

    int property_impl::set( const char * lpszName, xos::xos_u64 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, xos::xos_i64 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, xos::xos_u32 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, xos::xos_i32 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, xos::xos_u16 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, xos::xos_i16 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set_u8( const char * lpszName, xos::xos_u8 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_u8( lpRef );
        return 0;
    }

    int property_impl::set_i8( const char * lpszName, xos::xos_i8 * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_i8( lpRef );
        return 0;
    }

    int property_impl::set_char_array( const char * lpszName, char * lpRef, int nBufSize )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_char_array( lpRef, nBufSize );
        return 0;
    }

    int property_impl::set_bin( const char * lpszName, char * lpRef, int nBufSize )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set_bin( lpRef, nBufSize );
        return 0;
    }

    int property_impl::set( const char * lpszName, double * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, float * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( const char * lpszName, bool * lpRef )
    {
        i_variant * pVt = get( lpszName, true );
        pVt->set( lpRef );
        return 0;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // named index helper
    // 

    i_variant * property_impl::remove( const char * lpszName )
    {
        VT_NAME_ITER iter = m_name_map.find( lpszName );
        i_variant * pVt = 0;
        if( iter != m_name_map.end() )
        {
            pVt = iter->second;
            m_name_map.erase( iter );
        }
        return pVt;
    }

    i_variant * property_impl::vt( const char * lpszName )
    {
        i_variant * pVt = get( lpszName, false );
        return pVt;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // id index get
    // 
    
    const char * property_impl::str( int nId, char * lpszValue, int nBufSize, int * lpnSizeNeeded )
    {
        i_variant * pV = vt( nId );
        const char * pR = 0;
        if( pV )
        {
            pR = pV->str( lpszValue, nBufSize, lpnSizeNeeded );
        }
        return pR;
    }

    xos::i_release * property_impl::obj( int nId, xos::i_release ** ppv )
    {
        i_variant * pV = vt( nId );
        xos::i_release * pR = 0;
        if( pV )
        {
            pR = pV->obj( ppv );
        }
        return pR;
    }

    xos_box::i_list * property_impl::list( int nId, xos_box::i_list ** ppv )
    {
        i_variant * pV = vt( nId );
        xos_box::i_list * pR = 0;
        if( pV )
        {
            pR = pV->list( ppv );
        }
        return pR;
    }

    i_property * property_impl::prop( int nId, i_property ** ppv )
    {
        i_variant * pV = vt( nId );
        i_property * pR = 0;
        if( pV )
        {
            pR = pV->prop( ppv );
        }
        return pR;
    }

    v_create property_impl::fun( int nId, v_create * pv )
    {
        i_variant * pV = vt( nId );
        v_create pR = 0;
        if( pV )
        {
            pR = pV->fun( pv );
        }
        return pR;
    }

    double property_impl::dbl( int nId, double * lpdValue )
    {
        i_variant * pV = vt( nId );
        double dl = 0.0;
        if( pV )
        {
            dl = pV->dbl( lpdValue );
        }
        return dl;
    }

    float property_impl::flt( int nId, float * lpfValue )
    {
        i_variant * pV = vt( nId );
        float ft = 0.0f;
        if( pV )
        {
            ft = pV->flt( lpfValue );
        }
        return ft;
    }

    int property_impl::it( int nId, int  * lpnValue )
    {
        i_variant * pV = vt( nId );
        int i = 0;
        if( pV )
        {
            i = pV->it( lpnValue );
        }
        return i;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // id index set
    // 

    int property_impl::set( int nId, const char * lpszValue )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpszValue );
        return 0;
    }

    int property_impl::set_obj( int nId, xos::i_release * pv, bool bAutoRelease )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_obj( pv, bAutoRelease );
        return 0;
    }

    int property_impl::set_list( int nId, xos_box::i_list * pv, bool bAutoRelease )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_list( pv, bAutoRelease );
        return 0;
    }

    int property_impl::set_prop( int nId, i_property * pv, bool bAutoRelease )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_prop( pv, bAutoRelease );
        return 0;
    }

    int property_impl::set( int nId, i_variant * pv )
    {
        i_variant * pVt = remove( nId );
        xos_stl::release_interface( pVt );
        m_id_map[nId] = pv;
        return 0;
    }

    int property_impl::set( int nId, v_create pv )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( pv );
        return 0;
    }

    int property_impl::set( int nId, double value )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( value );
        return 0;
    }

    int property_impl::set( int nId, float value )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( value );
        return 0;
    }

    int property_impl::set( int nId, int value )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( value );
        return 0;
    }

    int property_impl::set( int nId, xos::xos_u64 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, xos::xos_i64 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, xos::xos_u32 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, xos::xos_i32 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, xos::xos_u16 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, xos::xos_i16 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set_u8( int nId, xos::xos_u8 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_u8( lpRef );
        return 0;
    }

    int property_impl::set_i8( int nId, xos::xos_i8 * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_i8( lpRef );
        return 0;
    }

    int property_impl::set_char_array( int nId, char * lpRef, int nBufSize )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_char_array( lpRef, nBufSize );
        return 0;
    }

    int property_impl::set_bin( int nId, char * lpRef, int nBufSize )
    {
        i_variant * pVt = get( nId, true );
        pVt->set_bin( lpRef, nBufSize );
        return 0;
    }

    int property_impl::set( int nId, double * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, float * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    int property_impl::set( int nId, bool * lpRef )
    {
        i_variant * pVt = get( nId, true );
        pVt->set( lpRef );
        return 0;
    }

    xos::xos_u64 * property_impl::u64_ptr( int nId, xos::xos_u64 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_u64 * pRet = 0;
        if( pV )
        {
            pRet = pV->u64_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i64 * property_impl::i64_ptr( int nId, xos::xos_i64 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_i64 * pRet = 0;
        if( pV )
        {
            pRet = pV->i64_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_u32 * property_impl::u32_ptr( int nId, xos::xos_u32 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_u32 * pRet = 0;
        if( pV )
        {
            pRet = pV->u32_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i32 * property_impl::i32_ptr( int nId, xos::xos_i32 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_i32 * pRet = 0;
        if( pV )
        {
            pRet = pV->i32_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_u16 * property_impl::u16_ptr( int nId, xos::xos_u16 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_u16 * pRet = 0;
        if( pV )
        {
            pRet = pV->u16_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i16 * property_impl::i16_ptr( int nId, xos::xos_i16 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_i16 * pRet = 0;
        if( pV )
        {
            pRet = pV->i16_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_u8 * property_impl::u8_ptr( int nId, xos::xos_u8 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_u8 * pRet = 0;
        if( pV )
        {
            pRet = pV->u8_ptr( lppRet );
        }
        return pRet;
    }

    xos::xos_i8 * property_impl::i8_ptr( int nId, xos::xos_i8 ** lppRet )
    {
        i_variant * pV = vt( nId );
        xos::xos_i8 * pRet = 0;
        if( pV )
        {
            pRet = pV->i8_ptr( lppRet );
        }
        return pRet;
    }

    char * property_impl::char_array( int nId, char ** lppRet, int * lpnSize, int * lpnLen )
    {
        i_variant * pV = vt( nId );
        char * pRet = 0;
        if( pV )
        {
            pRet = pV->char_array( lppRet, lpnSize, lpnLen );
        }
        return pRet;
    }

    char * property_impl::bin_ptr( int nId, char ** lppRet, int * lpnSize, int * lpnLen )
    {
        i_variant * pV = vt( nId );
        char * pRet = 0;
        if( pV )
        {
            pRet = pV->bin_ptr( lppRet, lpnSize, lpnLen );
        }
        return pRet;
    }

    double * property_impl::dbl_ptr( int nId, double ** lppRet )
    {
        i_variant * pV = vt( nId );
        double * pRet = 0;
        if( pV )
        {
            pRet = pV->dbl_ptr( lppRet );
        }
        return pRet;
    }

    float * property_impl::flt_ptr( int nId, float ** lppRet )
    {
        i_variant * pV = vt( nId );
        float * pRet = 0;
        if( pV )
        {
            pRet = pV->flt_ptr( lppRet );
        }
        return pRet;
    }

    bool * property_impl::bool_ptr( int nId, bool ** lppRet )
    {
        i_variant * pV = vt( nId );
        bool * pRet = 0;
        if( pV )
        {
            pRet = pV->bool_ptr( lppRet );
        }
        return pRet;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // id index helper
    // 

    i_variant * property_impl::remove( int nId )
    {
        VT_ID_ITER iter = m_id_map.find( nId );
        i_variant * pVt = 0;
        if( iter != m_id_map.end() )
        {
            pVt = iter->second;
            m_id_map.erase( iter );
        }
        return pVt;
    }

    i_variant * property_impl::vt( int nId )
    {
        i_variant * pVt = get( nId, false );
        return pVt;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // other helper
    // 

    i_variant * property_impl::name_data( const char ** ppKey, char * lpszKey, int nBufSize, int * lpnSizeNeeded )
    {
        i_variant * pRet = 0;
        if( m_name_iter != m_name_map.end() )
        {
            pRet = m_name_iter->second;
        }
        if( pRet && ppKey )
        {
            *ppKey = m_name_iter->first.c_str();
        }
        if( pRet && lpszKey )
        {
            mgr::crt()->strcpy( lpszKey, nBufSize, m_name_iter->first.c_str() );
        }
        if( pRet && lpnSizeNeeded )
        {
            *lpnSizeNeeded = ( int )( m_name_iter->first.length() + 1 );
        }
        return pRet;
    }

    i_variant * property_impl::id_data( int * pnId )
    {
        i_variant * pRet = 0;
        if( m_id_iter != m_id_map.end() )
        {
            pRet = m_id_iter->second;
        }
        if( pRet && pnId )
        {
            *pnId = m_id_iter->first;
        }
        return pRet;
    }

    int property_impl::name_next()
    {
        int ret = 0;
        if( m_name_iter != m_name_map.end() )
        {
            m_name_iter++;
        }
        return ret;
    }

    int property_impl::id_next()
    {
        int ret = 0;
        if( m_id_iter != m_id_map.end() )
        {
            m_id_iter++;
        }
        return ret;
    }

    int property_impl::reset()
    {
        int ret = 0;
        m_name_iter = m_name_map.begin();
        m_id_iter = m_id_map.begin();
        return ret;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    int property_impl::size( int * pNamePropSize, int * pIdPropSize )
    {
        int ret = 0;

        if( pNamePropSize )
        {
            *pNamePropSize = ( int )m_name_map.size();
        }

        if( pIdPropSize )
        {
            *pIdPropSize = ( int )m_id_map.size();
        }

        return ret;
    }

    int property_impl::release_all()
    {
        int ret = 0;

        for( VT_NAME_ITER iter = m_name_map.begin(); iter != m_name_map.end(); ++iter )
        {
            i_variant * p = iter->second;
            p->release();
        }
        m_name_map.clear();

        for( VT_ID_ITER iter = m_id_map.begin(); iter != m_id_map.end(); ++iter )
        {
            i_variant * p = iter->second;
            p->release();
        }
        m_id_map.clear();

        return ret;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    i_variant * property_impl::get( const char * lpszName, bool bCreate )
    {
        VT_NAME_ITER iter = m_name_map.find( lpszName );
        i_variant * pVt = 0;
        if( iter != m_name_map.end() )
        {
            pVt = iter->second;
        }
        else if( bCreate )
        {
            variant_impl * p = variant_impl::get_item_from_pool( true );
            p->init();
            pVt = p;
            m_name_map[lpszName] = pVt;
        }
        return pVt;
    }

    i_variant * property_impl::get( int nId, bool bCreate )
    {
        VT_ID_ITER iter = m_id_map.find( nId );
        i_variant * pVt = 0;
        if( iter != m_id_map.end() )
        {
            pVt = iter->second;
        }
        else if( bCreate )
        {
            variant_impl * p = variant_impl::get_item_from_pool( true );
            p->init();
            pVt = p;
            m_id_map[nId] = pVt;
        }
        return pVt;
    }

} // xos_common
